﻿using System.IO;
using ICSharpCode.SharpZipLib.Zip;

namespace ComicTool.Model
{
    public class ZipCompressedPage : Page
    {
        private Stream stream;
        private ZipEntry entry;

        internal ZipCompressedPage(Stream parentStream, ZipEntry entry)
        {
            this.entry = entry;
            this.stream = parentStream;
        }

        public override string Name
        {
            get
            {
                return entry.Name;
            }
        }

        public override byte[] ExtractBytes()
        {
            using (ZipFile zf = new ZipFile(stream))
            {
                zf.IsStreamOwner = false;
                MemoryStream output = new MemoryStream();
                zf.GetInputStream(entry).TransferTo(output);
                output.Position = 0;
                return output.ToArray();
            }
        }
    }
}
